package cn.hl.sfzy.controller;

import cn.hl.sfzy.entity.Course;
import cn.hl.sfzy.entity.CourseType;
import cn.hl.sfzy.entity.User;
import cn.hl.sfzy.service.CourseService;
import cn.hl.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CourseController
 * @Description TODO
 * @Author libowen
 * @Date 2024年10月25日 10:27
 * @Version 1.0
 */
@RestController
@RequestMapping("/Course")
@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping("/findById")
    public Result findById(Long id){
        Course course = courseService.findById(id);
        return Result.success(course);
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        int i = courseService.deleteCourse(id);
        return Result.success("删除成功");
    }
    @PostMapping
    public Result insert(@RequestBody Course course) {
        int i = courseService.addCourse(course);
        return Result.success(course);
    }
    @PutMapping
    public Result update(@RequestBody Course course) {
        int i = courseService.updateCourse(course);
        return Result.success(course);
    }
    @GetMapping("/findByPage")
    public Result pageSelect(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "5") int pageSize, Course course) {
        PageInfo<Course> byPage = courseService.findByPage(pageNum, pageSize, course);
        return Result.success(byPage);
    }

    @GetMapping("/find")
    public Result select(Course course) {
        List<Course> courses = courseService.getCourses(course);
        return Result.success(courses);
    }
    @GetMapping("/selectByConsultId")
    public Result selectByConsultId(@RequestParam(required = false,defaultValue = "1") int pageNum, @RequestParam(required = false,defaultValue = "3") int pageSize, Long teacher_id) {
        PageInfo<Course> byPage=courseService.selectByConsultId(pageNum, pageSize, teacher_id);
        return Result.success(byPage);
    }
}
